package com.mt.grand.prototype.clone;

import com.mt.grand.prototype.dto.PrototypeObject1;
import com.mt.grand.prototype.dto.PrototypeObject2;

/**
 * 原型模式实例
 * 可以通过序列化的方式进行深度复制
 */
public class deep {

    public static void main(String[] args) throws CloneNotSupportedException {
        PrototypeObject2 prototypeObject2 = new PrototypeObject2();
        PrototypeObject1 prototypeObject1 = new PrototypeObject1();
        prototypeObject1.setDesc("prototypeObject1");
        prototypeObject1.setName("prototypeObject1");
        prototypeObject1.setPrototypeObject2(prototypeObject2);

        PrototypeObject1 clone = (PrototypeObject1)prototypeObject1.clone();

        System.out.println(prototypeObject1 == clone);

        System.out.println(prototypeObject1.getPrototypeObject2() == clone.getPrototypeObject2());
    }

}